package com.honghu.villagepost.activity.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.blankj.utilcode.util.PhoneUtils
import com.honghu.villagepost.R
import com.honghu.villagepost.activity.StoreDetailsActivity
import com.honghu.villagepost.api.ApiService
import com.honghu.villagepost.base.BaseFragment
import com.honghu.villagepost.callback.DialogCallback
import com.honghu.villagepost.callback.LzyResponse
import com.honghu.villagepost.constant.Constants
import com.honghu.villagepost.entity.Store
import com.lzy.okgo.model.Response
import kotlinx.android.synthetic.main.fragment_store_details.*


/**
 * @author: mqwang
 * @create: 1/26/21 10:19 AM
 * @Description: 逛城市fragment
 */
class StoreDetailsFragment : BaseFragment() {

    private var shopId: Int? = 0

    companion object {
        fun newInstance(shopId: Int): StoreDetailsFragment {
            val fragment = StoreDetailsFragment()
            val bundle = Bundle()
            bundle.putInt(Constants.SHOP_ID, shopId)
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun initViews(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
        val view = inflater!!.inflate(R.layout.fragment_store_details, container, false)
        return view
    }


    override fun initData() {
        shopId = arguments!!.getInt(Constants.SHOP_ID)
        ApiService.shop_id(this, shopId!!, object : DialogCallback<LzyResponse<Store>>() {
            override fun onSuccess(response: Response<LzyResponse<Store>>?) {
                var store = response!!.body().data
                tv_store_name.setText(store.name)
                tv_addr.setText("地址:" + store.province + store.city + store.district + store.address)

                tv_phone.setOnClickListener {
                    PhoneUtils.dial(store.principalMobile)
                }

                if (activity is StoreDetailsActivity) {
                    (activity as StoreDetailsActivity).updateStoreDetail(store)
                }
            }

        })
    }
}